package Day2025_04_07;

import java.util.HashSet;
import java.util.Set;

public class Demo02 {
    public int maxLength (int[] arr) {
        // write code here
        int n = arr.length;
        int maxLen = -0x3f3f3f3f;
        Set<Integer> hash = new HashSet<>();
        for (int left = 0, right = 0; right < n; ) {
            int in = arr[right];
            if (!hash.contains(in)) {
                hash.add(in);
                right++;
                maxLen = Math.max(right - left, maxLen);
            } else {
                int out = arr[left++];
                hash.remove(out);
            }
        }
        return maxLen;
    }
}
